# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgname=roundcubemail
pkgver=1.6.5
pkgrel=1
pkgdesc="A PHP web-based mail client"
arch=('any')
url="https://roundcube.net/"
license=('GPL')
depends=('php-interpreter')
options=('emptydirs')
makedepends=('git')
optdepends=('python: password change script'
            'perl: for change_ldap_pass.pl helper'
	    'php-gd')
backup=('etc/webapps/roundcubemail/.htaccess'
        'etc/webapps/roundcubemail/apache.conf')
install=roundcube.install
validpgpkeys=('F3E4C04BB3DB5D4215C45F7F5AB2BAA141C4F7D5')
source=("https://github.com/roundcube/roundcubemail/releases/download/$pkgver/roundcubemail-$pkgver-complete.tar.gz"{,.asc}
        "apache.conf")
sha512sums=('d5d108045dc0afcc1fda077cac82f3aef274702727d45395744a3228c2a0429199d411f1988fc3f8317040ce65735ba423e8a1a33bad77220d63821e8b29ae08'
            'SKIP'
            '0e80317ae6f040386b0980d0764bc8a9aa5f7cbf028a210a896763cb7a7fea6d91600eda588922a0eb6d519f2ec1e0a2f723bd7ab554c8b1ad4af49a95101f6e')

prepare() {
  cd "$srcdir"/roundcubemail-${pkgver}
  sed -i \
    -e "s|RCUBE_INSTALL_PATH . 'temp.*|'/var/cache/roundcubemail';|" \
    -e "s|RCUBE_INSTALL_PATH . 'logs.*|'/var/log/roundcubemail';|" \
    config/defaults.inc.php \
    program/lib/Roundcube/rcube_config.php
}

package() {
  mkdir -p "$pkgdir"/etc/webapps/roundcubemail
  mkdir -p "$pkgdir"/usr/share/webapps
  cd "$pkgdir"/usr/share/webapps
  cp -ra "$srcdir"/roundcubemail-${pkgver} roundcubemail
  cd roundcubemail

  mv .htaccess "$pkgdir"/etc/webapps/roundcubemail/
  ln -s /etc/webapps/roundcubemail/.htaccess .htaccess

  mv config "$pkgdir"/etc/webapps/roundcubemail/
  ln -s /etc/webapps/roundcubemail/config config

  install -Dm0644 "$srcdir"/apache.conf "$pkgdir"/etc/webapps/roundcubemail/apache.conf
  chown 33:33 "$pkgdir"/etc/webapps/roundcubemail/config/config.inc.php.sample
  chmod 0640 "$pkgdir"/etc/webapps/roundcubemail/config/config.inc.php.sample

  install -dm0750 -o 33 -g 33 "$pkgdir"/var/cache/roundcubemail
  install -dm0750 -o 33 -g 33 "$pkgdir"/var/log/roundcubemail

  rm -rf temp logs
}
